﻿using CoreShop.Library;
using Sunny.UI;

namespace CoreShop.App
{
    public partial class FKeyBoard : UIForm
    {        
        public const int WM_CHAR = 256;
        public UITextBox edit = null;
        public UIToolStripDropDown MyKeyboardEx = null;
        public FKeyBoard()
        {
            InitializeComponent();
            MyKeyboardEx = new UIToolStripDropDown(new UIKeyboardEx((UIEdit)uiTextBox1.TextBox));
        }

        public delegate void OnOkButtonClick(object sender, string value);
        public event OnOkButtonClick OkButtonClick;
        public delegate void OnValueChanged(object sender, string value);
        public event OnValueChanged ValueChanged;

        private void NumBoardForm_ValueChanged(object sender, object value)
        {
            int start = edit.SelectionStart;
            switch ((int)value)
            {
                case 95:
                    edit.Text = edit.Text.Left(start) + "-" + edit.Text.Middle(start, edit.Text.Length);
                    start += 1;
                    edit.SelectionStart = start;
                    edit.Select(start, 0);
                    break;
                case 46:
                    edit.Text = edit.Text.Left(start) + "." + edit.Text.Middle(start, edit.Text.Length);
                    start += 1;
                    edit.SelectionStart = start;
                    edit.Select(start, 0);
                    break;
                case 13:
                    OkButtonClick?.Invoke(this, Text);
                    break;
                default:
                    Sunny.UI.Win32.User.PostMessage(edit.Handle, WM_CHAR, (int)value, 0);
                    edit.SelectionStart = start;
                    edit.Select(start, 0);
                    //ValueChanged?.Invoke(this, Text);
                    //this.Focus();
                    break;
            }
            //DoValueChanged?.Invoke(this, null);
        }

        private void uiButton1_Click(object sender, System.EventArgs e)
        {
            uiButton1.Selected = false;
            uiButton2.Selected = false;
            UIButton btn = (UIButton)sender;
            btn.Selected = true;
        }

        private void uiButton4_Click(object sender, System.EventArgs e)
        {
            uiButton4.Selected = false;
            uiButton3.Selected = false;
            UIButton btn = (UIButton)sender;
            btn.Selected = true;
        }

        private void btnExit_Click(object sender, System.EventArgs e)
        {
            this.Close();
        }

        private void uiButton23_Click(object sender, System.EventArgs e)
        {
            MyKeyboardEx.ValueChanged += MoreMenu_ValueChanged;
            MyKeyboardEx.Show(uiPanel4, 0, 0);
        }

        private void MoreMenu_ValueChanged(object sender, object value)
        {

        }

        private void FKeyBoard_Load(object sender, System.EventArgs e)
        {

        }
    }
}
